/*
 * Created on 3 août 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.jade.util.log.handler;

import java.io.File;
import java.io.FileWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @author ssicard
 */
public class FileHandler implements Handler{

	private FileWriter fw;
	
	public void start(){
		try{
		  // TODO use a PrintStream
			File f = new File("/tmp/ssicard-jade-logs.txt");
			f.createNewFile();
			fw = new FileWriter(f);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void stop(){
		try{
			fw.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void log(String msg) {
		try{
			GregorianCalendar cal = new GregorianCalendar();
			fw.write("~"+cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
			fw.write("~"+cal.getTimeInMillis()+"~");
			fw.write(msg+"\n");
			fw.flush();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
